<?php 
require 'config.php';
require 'inc/require.php';

$chip_id = Session::get('chip_id');

if(isset($_GET['pagetype']) && !empty($_GET['pagetype'])) {
	
	if($_GET['pagetype'] == 'uitloggen'){
		Session::destroy();
		header('location: ' . URL);
		die();
	}
	$pagetype = $_GET['pagetype'];
} else if (empty($chip_id)){
	$pagetype = 'login';
} else {
	$pagetype = 'home';
}

// Inloggen
if(isset($_POST['submit'])){
	$validation = new Validation();
	$validation->validateChipId($_POST['chip_id']);

	if(!$validation->errors){
		$account = new Account();
		$account = $account->isValidUser($_POST['chip_id']);
		if($account){ /* Een geldig account */
			Session::set('account_id', $account->id);
			Session::set('chip_id', $account->chip_id);
		}
		header('location: ' . URL);
		die();
	}
}

switch ($pagetype) {
	case 'plattegrond':
		$require = 'map.php';
		break;
	case 'home':
		$require = 'nav.php';
		break;
	case 'saldo':
		$require = 'saldo.php';
		break;
	case 'berichten':
		$require = 'berichten.php';
		break;
	case 'attracties':
		$require = 'attracties.php';
		break;
	case 'login':
		$require = 'login.php';
		break;
	case 'fotoservice':
		$require = 'fotoservice.php';
		break;
	case 'fotoservice/gekocht':
		$require = 'fotoservice_gekocht.php';
		break;
	case 'delen':
		$require = 'delen.php';
		break;
	case 'help':
		$require = 'help.php';
		break;
	default:
		$require = '404.php';
		break;
}

?>


<!doctype html>
<html lang="en">

<head>
	<meta charset="utf-8" />
	<title>EftelingApplicatie</title>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <link rel="apple-touch-icon" href="img/appicon.png"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />	
	<!-- 1140px Grid styles for IE -->
	<!--[if lte IE 9]><link rel="stylesheet" href="css/ie.css" type="text/css" media="screen" /><![endif]-->

	<!-- The 1140px Grid - http://cssgrid.net/ -->
	<link rel="stylesheet" href="<?php echo URL?>css/1140.css" type="text/css" media="screen" />
		
	<!-- Your styles -->
	<link rel="stylesheet" href="<?php echo URL?>css/styles.css" type="text/css" media="screen" />
	
	<!-- JQUERY UI CSS -->
	<link rel="stylesheet" href="<?php echo URL?>css/ui-lightness/jquery-ui-1.8.20.custom.css" type="text/css" media="screen" />
	
	<!--css3-mediaqueries-js - http://code.google.com/p/css3-mediaqueries-js/ - Enables media queries in some unsupported browsers-->
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
	<script type="text/javascript" src="<?php echo URL?>js/css3-mediaqueries.js"></script>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyB5jAFA6GvoPSzqQUx4Jb7oOBGDyP5n9S0&sensor=false"></script>
    <script src="<?php echo URL?>js/infobox.js" type="text/javascript"></script>
	<script src="<?php echo URL?>js/jquery-ui-1.8.20.custom.min.js" type="text/javascript"></script>
	<!-- Inloggen voor saldo -->
	<script src="<?php echo URL?>js/inloggen_saldo.js" type="text/javascript"></script>
<script>
	// Mobile Safari in standalone mode
	if(("standalone" in window.navigator) && window.navigator.standalone){
	
	// If you want to prevent remote links in standalone web apps opening Mobile Safari, change 'remotes' to true
	var noddy, remotes = false;
	
	document.addEventListener('click', function(event) {
	
	noddy = event.target;
	
	// Bubble up until we hit link or top HTML element. Warning: BODY element is not compulsory so better to stop on HTML
	while(noddy.nodeName !== "A" && noddy.nodeName !== "HTML") {
	noddy = noddy.parentNode;
	}
	
	if('href' in noddy && noddy.href.indexOf('http') !== -1 && (noddy.href.indexOf(document.location.host) !== -1 || remotes))
	{
	event.preventDefault();
	document.location.href = noddy.href;
	}
	
	},false);
	}
</script>
<script>
 window.addEventListener("load",function() {
   setTimeout(function(){
    window.scrollTo(0, 0);
    }, 0);
 });
</script>

</head>
<input type="hidden" name="URL" value="<?= URL ?>" />
<body>
	<div class="container">
		<?php require ('inc/' . $require); ?>
	</div>
</body>

</html>